package reflect;

import java.util.Scanner;

public class ReflectDemo2 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        //获取类对象
        Class cls = Class.forName("java.util.ArrayList");
        //类对象提供了实例化的操作
        Object obj = cls.newInstance();
        System.out.println(obj);

        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("请输入类对象：");
            String className = sc.nextLine();
            if (className.equals("exit")) {
                break;
            }
            Class cls1 = Class.forName(className);
            Object obj1 = cls1.newInstance();
            System.out.println(obj1);
        }
    }
}
